#!/usr/bin/env python
"""
This Creates links in /usr/bin to *.py with EXEC permission in current directory
(including itself, if the case).

Please note that you should probably run this as root.
"""

import glob
import os
import logging

def MakeLinks():
    #me = os.path.basename(__file__)
    files = glob.glob('*.py')
    
    for file in files:
        if os.access(file, os.X_OK):
            print "Creating link for file \"%s\"..." % file
            fullfile = os.path.abspath(file)
            s = "ln -s %s /usr/bin/%s" % (fullfile, file)
            print "  $ "+s
            os.system(s)
        else:
            print "Skipping file \"%s\"" % file

if __name__ == "__main__":
    print __doc__
    s = raw_input("Please type \"yes\" if you want this to happen: ")
    if s == "yes":
        print "Ok, so be it!"
        MakeLinks()
    else:
        print "Ok, bye then."
    
